﻿using CgdataBase;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;

namespace FolderCompare.ViewModels
{
    public class WinAboutViewModel : BindableBase
    {
        private AppSettings Settings => AppSettings.Instance;
        public int FontSize => Settings.FontSize;
        public string FontName => Settings.FontName;
        public string Title => "关于";
        public string ApplicationName => Properties.Resources.ApplicationName;
        public string Version => Assembly.GetExecutingAssembly().GetName().Version.ToString(3);
        public string HomePageUrl => "https://www.cnblogs.com/wzwyc/";
        public string ReleaseNote { get; set; }

        public DelegateCommand OpenUrlCommand { get; }

        public WinAboutViewModel()
        {
            OpenUrlCommand = new DelegateCommand(OnOpenUrl);

            LoadReleaseNote();
        }

        private void LoadReleaseNote()
        {
            var fileName = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "ReleaseNote.txt");
            if (File.Exists(fileName))
            {
                ReleaseNote = File.ReadAllText(fileName, Encoding.UTF8);
            }
        }

        private void OnOpenUrl()
        {
            Process.Start(new ProcessStartInfo(HomePageUrl) { UseShellExecute = true });
        }
    }
}